import { request } from '@umijs/max';

export async function login(params: any) {
  return request('/common/login/form', {
    method: 'POST',
    getResponse: true,
    transformRequest: (data) => {
      let result = [];
      // eslint-disable-next-line guard-for-in
      for (let key in data) {
        result.push(
          encodeURIComponent(key) + '=' + encodeURIComponent(data[key]),
        );
      }
      return result.join('&');
    },
    data: params,
  });
}

// 发送验证码
export async function getPhoneCode(mobile: string) {
  return request(`/common/check-code/login?mobile=${mobile}`, {
    method: 'get',
  });
}
// 获取用户信息
export async function getUserInfo() {
  return request('/common/user', { method: 'get' });
}
// 获取账户信息
export async function getUserAccount() {
  return request('/base/user-account', { method: 'get' });
}

// 重置密码
export async function resetPassword(params: {
  checkCode: string;
  mobile: string;
  password: string;
  repeatPassword: string;
}) {
  return request('/common/user/reset-password', {
    method: 'put',
    data: params,
    getResponse: true,
  });
}

// 退出登录
export async function logout() {
  return request('/common/logout', {
    method: 'get',
    getResponse: true,
  });
}

// 注册
export async function register(params: any) {
  return request('common/register/partner-register', {
    method: 'POST',
    getResponse: true,
    data:params
  });
}

